package com.landleaf.smarthome;

import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;

import com.gyf.barlibrary.BarHide;
import com.gyf.barlibrary.ImmersionBar;
import com.landleaf.smarthome.net.hardware.ProtocolUtils;
import com.landleaf.smarthome.net.http.ApiFactory;
import com.landleaf.smarthome.net.mqtt.MqttExecutor;

import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_BAR).init();
        setContentView(R.layout.activity_main);
        ImageView imageView = findViewById(R.id.iv);

        imageView.setOnClickListener(l -> {
            test();
            imageView.setBackgroundResource(R.drawable.test_2);
        });
        findViewById(R.id.textView).setOnClickListener(v -> {
            MqttExecutor.getInstance().connect();
        });
        findViewById(R.id.textView3).setOnClickListener(v -> {
            MqttExecutor.getInstance().sendSecurityAlarmMsg(null);
        });
        findViewById(R.id.textView2).setOnClickListener(v -> {
            MqttExecutor.getInstance().sendDeviceUpdateMsg(null);
        });
        findViewById(R.id.textView4).setOnClickListener(v -> {
            MqttExecutor.getInstance().sendSceneUpdateMsg(null);
            int[] ids = {0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1};
            List<Integer> adds = ProtocolUtils.getFaults4FaultAdds(ids);
            adds.size();
        });
    }

    void test() {
        ApiFactory.getNetApi().getWeather().subscribeOn(Schedulers.io())//在IO线程执行数据库处理操作
                .observeOn(AndroidSchedulers.mainThread()).subscribe(l -> {


        }, e -> {
            Log.d("hh", e.getMessage());
        });

    }


}
